package com.hcc.repository.gen.generator.impl;

import com.hcc.repository.gen.config.GlobalConfig;
import com.hcc.repository.gen.config.PackageConfig;
import com.hcc.repository.gen.constants.GenerateTypeConstants;
import com.hcc.repository.gen.generator.AbstractGenerator;
import com.hcc.repository.gen.model.TableMetadata;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * MapperGenerator
 *
 * @author hushengjun
 * @date 2023/9/28
 */
public class RepositoryImplGenerator extends AbstractGenerator {

    @Override
    public String generateType() {
        return GenerateTypeConstants.REPOSITORY_IMPL;
    }

    @Override
    protected boolean needGenerate(GlobalConfig globalConfig) {
        return globalConfig.isEnableGenerateRepositoryImpl();
    }

    @Override
    protected boolean needOverride(GlobalConfig globalConfig) {
        return globalConfig.getRepositoryImplConfig().isEnableOverride();
    }

    @Override
    protected String getPackageFileName(TableMetadata tableMetadata, GlobalConfig globalConfig) {
        PackageConfig packageConfig = globalConfig.getPackageConfig();

        return packageConfig.getRepositoryImplPackage().replace(".", File.separator)
                + File.separator
                + tableMetadata.getRepositoryImplClassName()
                + ".java";
    }

    @Override
    protected Map<String, Object> getDataModel(TableMetadata tableMetadata, GlobalConfig globalConfig) {
        Map<String, Object> dataModel = new HashMap<>(4);
        dataModel.put("table", tableMetadata);
        dataModel.put("repositoryImplConfig", globalConfig.getRepositoryImplConfig());
        dataModel.put("packageConfig", globalConfig.getPackageConfig());
        dataModel.put("javadocConfig", globalConfig.getJavaDocConfig());

        return dataModel;
    }

}
